//
//  YMVCommentTableViewCell.m
//  STL_ Animation
//
//  Created by DJtd on 16/4/4.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "YMVCommentTableViewCell.h"

@implementation YMVCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor blackColor];
        
        self.headImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.commentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.updateTime = [[UILabel alloc] initWithFrame:CGRectZero];
        self.niceButton = [UIButton buttonWithType:UIButtonTypeSystem];
        
         [self.niceButton setImage:[[UIImage imageNamed:@"zan1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        
        self.nameLabel.font = [UIFont systemFontOfSize:15];
        self.commentLabel.font = [UIFont systemFontOfSize:14];
        self.updateTime.font = [UIFont systemFontOfSize:12];

        self.nameLabel.textColor = [UIColor lightGrayColor];
        self.commentLabel.textColor = [UIColor whiteColor];
        self.updateTime.textColor = [UIColor grayColor];
        
        self.commentLabel.numberOfLines = 0;
        
        [self addSubview:self.headImage];
        [self addSubview:self.nameLabel];
        [self addSubview:self.commentLabel];
        [self addSubview:self.updateTime];
        [self addSubview:self.niceButton];

    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.headImage.frame = CGRectMake(10, 0, 50, 50);
    [self.headImage.layer setCornerRadius:25];
    self.layer.masksToBounds = YES;
    
    self.nameLabel.frame = CGRectMake(70, 10, BoundsWidth / 2, 30);
    self.updateTime.frame = CGRectMake(10, BoundsHeight - 20, BoundsWidth / 4, 20);
    self.niceButton.frame = CGRectMake(BoundsWidth - 30, BoundsHeight - 30, 20, 20);
}

- (void)setCommentModel:(YMVCommentModel *)commentModel {
    _commentModel = commentModel;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:commentModel.userHeadImg] placeholderImage:[UIImage imageNamed:@"YMVPlace1"]];
    self.nameLabel.text = commentModel.userName;
    self.updateTime.text = commentModel.dateCreated;
    self.commentLabel.text = commentModel.content;
    
    self.commentLabel.frame = CGRectMake(5, 10, ScreenWidth / 3 * 2, [self cellHeight]);
    
}

- (CGFloat)cellHeight{
    // 字体以及大小
    NSDictionary *fontDic = [NSDictionary dictionaryWithObject:self.commentLabel.font forKey:NSFontAttributeName];
    // 计算宽高
    CGSize size = [self.commentLabel.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width / 3 * 2, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:fontDic context:nil].size;
    // 返回计算完成的高度
    return size.height + 91;
}

@end
